﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using WebApplication1.Business;

namespace WebApplication1
{
    public partial class Site1 : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Panel2.Visible = false;
            Panel3.Visible = false;
            Label1.Text = DateTime.Today.DayOfWeek.ToString();
            Label2.Text = DateTime.Now.ToShortDateString();
            if (Session["user"] != null)
            {
                Panel1.Visible = false;
                Panel2.Visible = true;
                Panel3.Visible = true;
                Label5.Text = "Hi " + Session["user"].ToString()+" ,wellcome you ! If you want to log out,click  ";
            }
        }
        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            if (Session["user"] != null)
            {
                Session.Remove("user");
                Response.Redirect("Homes.aspx");
            }
        }

        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {
            UserBusiness ub = new UserBusiness();
            bool flag1 = ub.Check(TextBox1.Text, App.Encrypt(TextBox2.Text),true);
            bool flag2 = ub.Check(TextBox1.Text, App.Encrypt(TextBox2.Text), false);
            HttpCookie cookie = new HttpCookie("cookie");
            Response.Cookies.Remove("cookie");
            Response.Cookies.Add(cookie);
            cookie.Values.Add("user", TextBox1.Text);
            cookie.Values.Add("pass", App.Encrypt(TextBox2.Text));
            Session["user"] = TextBox1.Text;
            Session["pass"] = App.Encrypt(TextBox2.Text);   
            if (flag1)
            {                                     
                Response.Redirect("Admin.aspx");
            }

            else if (flag2)
            {
                Response.Redirect("Index.aspx");
            }
            else
            {
                App.showMessage(this.Page,GetType(),"Incorrect UserID or password!",false);
                Session["user"] = null;
                Session["pass"] = null;
            }
        }
    }
}
